﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SPIWareMVVM.ViewModels;
using System.Windows;
using DataAccess;

namespace SPIWareMVVM.Views.Commands
{
    public class ShowMaterialsListCommand : BaseCommand
    {
        public ShowMaterialsListCommand(BaseViewModel sender)
            : base(sender)
        {
            _sender = (ApplicationViewModel)sender;
        }

        public override void Execute(object parameter)
        {
            MaterialList list = (MaterialList)parameter;
            if (list != null)
            {
                if (mainWindow == null) mainWindow = (Window1)Window.GetWindow((MaterialList)list);
                ApplicationData.SelectedCustomer = null;
                if (mainWindow != null)
                {
                    ApplicationData.ClearSelected(ApplicationData.AllSelectable);
                    mainWindow.HideLists();
                }

                list.lbMaterials.ItemsSource = null;
                list.lbMaterials.ItemsSource = ApplicationData.SelectedCustomer == null
                    ? ApplicationData.ocParts
                    : ApplicationData.localParts();

                list.lbMaterials.SelectedIndex = -1;

                mainWindow.materialsList.Visibility = Visibility.Visible;
            }
        }
    }
}
